const { Controller } = require('egg')

class TriggerController extends Controller {
  /**
   * @return {object} 树形选择菜单数据获取
   */
  async tree() {
    const { type, term } = this.ctx.data

    let tree
    if (type === 'class') {
      tree = await this.service.tree.class_(term)
    } else if (type === 'teacher') {
      tree = await this.service.tree.teacher(term)
    }
    else if (type === 'classroom') {
      tree = await this.service.tree.classroom(term)
    }
    this.ctx.body = {
      code: 200,
      data: {
        tree,
      },
    }
  }
}

module.exports = TriggerController
